package org.misalen.web.server.controllers;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.misalen.annotations.ControllerApi;
import org.misalen.annotations.InterfaceApi;
import org.misalen.web.server.config.ServerResult;
import org.misalen.web.server.result.Empty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@ControllerApi(value = "查看版本及服务", description = "")
@RequestMapping(value = "/look")
public class LookOverController extends BaseController {

	@RequestMapping(value = "", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
	@InterfaceApi(value = "初始化配置", resultClass = Empty.class)
	public void look(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Properties prop = new Properties();
		InputStream in = getClass().getResourceAsStream("/jdbc.properties");

		prop.load(in);
		String mysqlUrl = prop.getProperty("jdbc.url").trim();
		boolean release = mysqlUrl.lastIndexOf("test") == -1;
		Map<String, Object> map = new HashMap<>();
		map.put("mysqlUrl", mysqlUrl);
		map.put("release", release);
		ServerResult.ok(map);

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>look</title>");
		out.println("</head>");
		out.println("<body>");

		out.println("release:<h1 style='display:inline-block;'>");
		out.println(release);
		out.println("</h1><br>");

		out.println("mysqlUrl:<h1 style='display:inline-block;'>");
		out.println(mysqlUrl);
		out.println("</h1><br>");

		out.println("</body>");
		out.println("</html>");
	}

}
